/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jpa.entities;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author innovapps.co
 */
@Entity
@Table(name = "certificacion")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Certificacion.findAll", query = "SELECT c FROM Certificacion c"),
    @NamedQuery(name = "Certificacion.findByIdCertificacion", query = "SELECT c FROM Certificacion c WHERE c.idCertificacion = :idCertificacion"),
    @NamedQuery(name = "Certificacion.findByDescr", query = "SELECT c FROM Certificacion c WHERE c.descr = :descr"),
    @NamedQuery(name = "Certificacion.findByFecha", query = "SELECT c FROM Certificacion c WHERE c.fecha = :fecha")})
public class Certificacion implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_certificacion")
    private Integer idCertificacion;
    @Basic(optional = false)
    @Column(name = "descr")
    private String descr;
    @Basic(optional = false)
    @Column(name = "fecha")
    @Temporal(TemporalType.DATE)
    private Date fecha;
    @JoinColumn(name = "maquina_id_maquina", referencedColumnName = "id_maquina")
    @ManyToOne(optional = false)
    private Maquina maquinaIdMaquina;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "certificacionIdCertificacion")
    private List<Ensayo> ensayoList;

    public Certificacion() {
    }

    public Certificacion(Integer idCertificacion) {
        this.idCertificacion = idCertificacion;
    }

    public Certificacion(Integer idCertificacion, String descr, Date fecha) {
        this.idCertificacion = idCertificacion;
        this.descr = descr;
        this.fecha = fecha;
    }

    public Integer getIdCertificacion() {
        return idCertificacion;
    }

    public void setIdCertificacion(Integer idCertificacion) {
        Integer oldIdCertificacion = this.idCertificacion;
        this.idCertificacion = idCertificacion;
        changeSupport.firePropertyChange("idCertificacion", oldIdCertificacion, idCertificacion);
    }

    public String getDescr() {
        return descr;
    }

    public void setDescr(String descr) {
        String oldDescr = this.descr;
        this.descr = descr;
        changeSupport.firePropertyChange("descr", oldDescr, descr);
    }

    public Date getFecha() {
        return fecha;
    }

    public void setFecha(Date fecha) {
        Date oldFecha = this.fecha;
        this.fecha = fecha;
        changeSupport.firePropertyChange("fecha", oldFecha, fecha);
    }

    public Maquina getMaquinaIdMaquina() {
        return maquinaIdMaquina;
    }

    public void setMaquinaIdMaquina(Maquina maquinaIdMaquina) {
        Maquina oldMaquinaIdMaquina = this.maquinaIdMaquina;
        this.maquinaIdMaquina = maquinaIdMaquina;
        changeSupport.firePropertyChange("maquinaIdMaquina", oldMaquinaIdMaquina, maquinaIdMaquina);
    }

    @XmlTransient
    public List<Ensayo> getEnsayoList() {
        return ensayoList;
    }

    public void setEnsayoList(List<Ensayo> ensayoList) {
        this.ensayoList = ensayoList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCertificacion != null ? idCertificacion.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Certificacion)) {
            return false;
        }
        Certificacion other = (Certificacion) object;
        if ((this.idCertificacion == null && other.idCertificacion != null) || (this.idCertificacion != null && !this.idCertificacion.equals(other.idCertificacion))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return descr + ". " + fecha;
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
